﻿/// <reference path="../../../common/js/jquery-1.10.2.min.js" />

var ClubAction = (function () {

    var _handler = function () {
        return "part/comment_part.html?v=" + Math.random();
    }

    var _addPost = function (content, images, local, success) {
        $.get(
            _handler(),
            { Action: "AddPost", Content: content, Images: images, Local: local },
            function (data) {
                var result = $.parseJSON(data);
                if (result.PostID > 0) {
                    if (typeof (success) != "undefined") {
                        success(result);
                    }
                }
            }
        );
    }

    var _addComment = function (postID, toUserID, toUserName, content, isReply, success) {
        $.post(
            "/guangqi/addcomment",
            { Action: "AddComment", Id: postID, ToUserID: toUserID, ToUserName: toUserName, Content: content, IsReply: isReply },
            function (data) {
                if (typeof (success) != "undefined") {
                    success(data);
                }
            }, "JSON"
        );
    }

    var _deleteComment = function (postID, commentID, messageID, success) {
        $.get(
            _handler(),
            { Action: "DeleteComment", PostID: postID, CommentID: commentID, MessageID: messageID },
            function (data) {
                if (typeof (success) != "undefined") {
                    success(data);
                }
            }
        );
    }

    var _register = function (userID, userName, sex, province, city, district, password, job, company, phone, email, success) {
        $.get(
            _handler(),
            {
                Action: "Register",
                UserID: userID,
                UserName: userName,
                Sex: sex,
                Province: province,
                City: city,
                District: district,
                Password: password,
                Job: job,
                Company: company,
                Phone: phone,
                Email: email
            },
            function (data) {
                if (typeof (success) != "undefined") {
                    success(data);
                }
            }
        );
    }

    var _praise = function (postID, userID, userName, success) {
        $.get(
            _handler(),
            { Action: "Praise", PostID: postID, UserID: userID, UserName: userName },
            success,
            "json"
        );
    }

    var _updateUserInfo = function (field, value, success) {
        $.get(
            _handler(),
            { Action: "UpdateUserInfo", Field: field, Value: value },
            success
        );
    }

    var _updateUserLocation = function (provinceID, cityID, districtID, success) {
        $.get(
            _handler(),
            { Action: "UpdateUserLocation", ProvinceID: provinceID, CityID: cityID, DistrictID: districtID },
            success
        );
    }

    var _changePassword = function (oldPass, newPass, success) {
        $.get(
            _handler(),
            { Action: "ChangePassword", OldPass: oldPass, NewPass: newPass },
            success,
            "json"
        );
    }

    var _sendCard = function (userID, userName) {

    }

    var _updateAvatarVersion = function (success) {
        if ($.cookie("avatar")) {
            var v = parseInt($.cookie("avatar")) + 1;
            $.cookie("avatar", v);
        } else {
            $.cookie("avatar", 1);
        }
    }

    var _userExists = function (userID, success) {
        $.get(
            _handler(),
            { Action: "UserExists", UserID: userID },
            success
        );
    }

    var _getHotCommentList = function (articleID, pageIndex, success) {
        $.get(
            "/guangqi/commenthotlist",
            { ID: articleID, Page: pageIndex },
            success
        );
    }

    var _getAllCommentList = function (articleID, success) {
        $.get(
            "/guangqi/commenttoplist",
            { Id: articleID },
            success
        );
    }

    return {
        AddPost: _addPost,
        AddComment: _addComment,
        DeleteComment: _deleteComment,
        Register: _register,
        Praise: _praise,
        UpdateUserInfo: _updateUserInfo,
        UpdateUserLocation: _updateUserLocation,
        ChangePassword: _changePassword,
        UpdateAvatarVersion: _updateAvatarVersion,
        UserExists: _userExists,
        GetHotCommentList: _getHotCommentList,
        GetAllCommentList: _getAllCommentList
    }
})();